<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div class="_contro">
    <a href="/home/action/" class="_a"><font style='font-size:1.5rem'>返回列表页</font></a>
</div>
<div class='_cut'></div>
<div class='content'>
    <?php if($actions['id'] && $copy == false){ ?>
    <form action="/home/action/update" method="post" id='form'>
        <?php }else{ ?>   
        <form action="/home/action/submit" method="post" id='form'>  
            <?php  }?>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">营销模式:</label>
                <select name="type" class='_select' id='type'>
                    <?php foreach($action_type as $v){?>
                    <option value="<?php echo $v['id']; ?>" id="model_type_<?php echo $v['id']; ?>" url="<?php echo $v['link']; ?>" <?php if($actions['model_type']==$v['id']){echo "selected='selected'";}?>><?php echo $v['model_name'];?></option>
                    <?php } ?>
                </select>
                <?php foreach($action_type as $v){ ?>
                <input type='hidden' id="model_<?php echo $v['id'];?>" value="<?php if($actions['model_type']==$v['id']){echo $actions['intro'];}else{echo $v['intro'];}?>"/>
                <?php } ?>
            </div>

            <div>
                <div class="form-group row">
                    <label for="exampleInputName2" class="_label" >店铺:</label>
                    <select id="store_id" name="store_id">
                        <option value='0'>全部</option>
                        <?php foreach($store as $v){?>
                        <option value='<?php echo $v['id'];?>' <?php if($actions['store_id']==$v['id']){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
                        <?php }?>
                    </select>
                </div>
            </div>
            <div id='barber_par'>
                <div class="form-group row" id='_barber'>
                    <label for="exampleInputName2" class="_label" >发型师:</label>
                    <select name="barber" class='_select' id="barber">
                        <option value="0">全部</option>
                        <?php if(isset($barber)){foreach($barber as $v){?>
                        <option value="<?php echo $v['id'];?>" <?php if($v['id']==$actions['barber_id']){echo "selected='selected'";}?>>
                            <?php echo $v['name'];?> </option>
                        <?php }}?>
                    </select>
                    <input type='button' value='添加' onclick="javascript:window.open('/home/barber/create');">
                    <span class='_prompt'>如果您想向客人推荐某位发型师或做专人营销活动请填选此处。</span>
                </div>
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">活动名称:</label>
                <?php if(!empty($actions)){?>
                <input type="text" class="row _minput" name='action_name' placeholder="" value="<?php echo $actions['action_name'];?>"/>
                <?php }else{?>
                <input type="text" class="row _minput" name='action_name' placeholder="" value=""/>
                <span class="_prompt">活动名称，主题 例如：“周年庆拼团活动”</span>
                <?php } ?>
            </div>
            
            <div id='type_model' >
                <div class='form-group row' id='item_name' > 
                    <label for="exampleInputName2" class="_label">活动项目:</label>
                    <?php $actions['content'] = json_decode($actions['content'],true); $arr=$actions['content']['content']; if($actions['id']<1 || $actions['content']['ids']!=false){?>
                    <select id="item_select" class="_select valid">
                        <option value='0'>请选择商品</option>
                    </select>
                    <input type="button" name="add_item" id="add_item" value="添加" />&nbsp;&nbsp;&nbsp;
                    <span> <a href="javascript:;"  id='create_good' >点击创建商品</a></span>
                    <?php }?>
                </div>
                <div class='form-group row' id='items' >
                    <?php $key=array_keys($arr); if(array_key_exists('help',$arr)){ $ke=array_pop($key); $hp=array_pop($arr); } { ?>
                    <?php if($_item!=false || $actions['id']<1){?>
                    <div class="row" id='item_list'>

                    <?php foreach($_item as $v){ ?>
                        <div class="col-sm-4 col-md-3 full">
                            <input type='hidden' id='items_<?php echo $v['id'];?>' value='<?php echo $v['id'];?>' name='items[]'>
                            <div class="thumbnail" style="margin-bottom:10px;">
                                <div style="height:21rem;overflow: hidden;text-align:center">
                                    <img class="_img" src="http://<?php echo IMAGE_DOMAIN.$v['images'][0]['image'];?>" style="width:100%;height:100%">
                                </div>
                            </div>
                            <div class="caption" style="overflow: hidden">
                                <div style="font-size:1.8rem">
                                    <div>
                                        <img class="_img" src="/public/images/<?php echo $v['img'];?>" style="width:28%;">
                                        <span style="margin-left: 6px;font-size:2rem;"><?php echo $v['name'];?></span>
                                    </div>
                                    <div>价格：<?php echo $v['price']/100;?></div><div>活动价：<input type="text" value="" style="width:30%" name="real_price[]">元</div>
                                    <div style="text-align:right"><a onclick="del_item(this,<?php echo $v['id'];?>);" href="#">删除</a></div>
                                </div>
                            </div> 
                        </div>
                    <?php }?>
                    </div>
                    <?php }else{?>
                    <label for="exampleInputName2" class="_label"><input type='text' style="width:50%" name='lf' id='lf' placeholder='项目名称'value="<?php echo $key[0] ?>">：</label><input type="text" name="lf_old" id="lf_old" placeholder="原价" value="<?php echo $arr["$key[0]"]['old']>0?$arr["$key[0]"]['old']/100:''?>">&nbsp;&nbsp;<input type="text" name="lf_new" id="lf_new" placeholder="现价" value="<?php echo $arr["$key[0]"]['new']>0?$arr["$key[0]"]['new']/100:''?>">&nbsp;&nbsp;<input type="text" style="width:30%" name="lf_con" id="lf_con" placeholder="拼团内容" value="<?php echo $arr["$key[0]"]['content']?>"><br/> 

                    <label for="exampleInputName2" class="_label"><input type='text' style="width:50%" name='tr' id='tr' placeholder='项目名称'value="<?php echo $key[1]?>">：</label><input type="text" name="tr_old" id="tr_old" placeholder="原价" value="<?php echo $arr["$key[1]"]['old']>0?$arr["$key[1]"]['old']/100:''?>">&nbsp;&nbsp;<input type="text" name="tr_new" id="tr_new" placeholder="现价" value="<?php echo $arr["$key[1]"]['new']>0?$arr["$key[1]"]['new']/100:''?>">&nbsp;&nbsp;<input type="text" style="width:30%" name="tr_con" id="tr_con" placeholder="拼团内容" value="<?php echo $arr["$key[1]"]['content']?>"><br/>

                    <label for="exampleInputName2" class="_label"><input type='text' style="width:50%" name='xh' id='xh' placeholder='项目名称'value="<?php echo $key[2]?>">：</label><input type="text" name="xh_old" id="xh_old" placeholder="原价" value="<?php echo $arr["$key[2]"]['old']>0?$arr["$key[2]"]['old']/100:''?>">&nbsp;&nbsp;<input type="text" name="xh_new" id="xh_new" placeholder="现价" value="<?php echo $arr["$key[2]"]['new']>0?$arr["$key[2]"]['new']/100:''?>">&nbsp;&nbsp;<input type="text" style="width:30%" name="xh_con" id="xh_con" placeholder="拼团内容" value="<?php echo $arr["$key[2]"]['content']?>"><br/>  

                    <label for="exampleInputName2" class="_label"><input type='text' style="width:50%" name='wm' id='wm' placeholder='项目名称'value="<?php echo $key[3]?>">：</label><input type="text" name="wm_old" id="wm_old" placeholder="原价" value="<?php echo $arr["$key[3]"]['old']>0?$arr["$key[3]"]['old']/100:''?>">&nbsp;&nbsp;<input type="text" name="wm_new" id="wm_new" placeholder="现价" value="<?php echo $arr["$key[3]"]['new']>0?$arr["$key[3]"]['new']/100:''?>">&nbsp;&nbsp;<input type="text" style="width:30%" name="wm_con" id="wm_con" placeholder="拼团内容" value="<?php echo $arr["$key[3]"]['content']?>"><br/>
                    <?php  } } ?>
                </div>
            </div>



            <div id='model'>
                <div class='form-group row'>
                    <label for="exampleInputName2" class="_label">活动开始日期:</label>
                    <?php if($actions['start_time']>0){?>
                    <input type="text" class="row _minput" name='start_time' placeholder="" value="<?php echo date('Y-m-d',$actions['start_time']);?>" onfocus="WdatePicker();" onblur=""/>
                    <?php }else{?>
                    <input type="text" class="row _minput" name='start_time' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
                    <?php }?>
                </div>
                <div class='form-group row'>
                    <label for="exampleInputName2" class="_label">活动结束日期:</label>
                    <?php if($actions['end_time']>0){?>
                    <input type="text" class="row _minput" name='end_time' placeholder="" value="<?php echo date('Y-m-d',$actions['end_time']);?>" onfocus="WdatePicker();" onblur=""/>
                    <?php }else{?>
                    <input type="text" class="row _minput" name='end_time' placeholder="" value="" onfocus="WdatePicker();" onblur=""/>
                    <?php }?>
                </div>
                <div class='form-group row'>
                    <label for="exampleInputName2" class="_label">使用截止日期:</label>
                    <?php if($actions['end_time']>0){?>
                    <input type="text" class="row _minput" name='use_end_time' placeholder="" value="<?php echo date('Y-m-d',$actions['use_end_time']);?>" onfocus="WdatePicker();" onblur=""  />
                    <?php }else{?>
                    <input type="text" class="row _minput" name='use_end_time' placeholder="" value="" onfocus="WdatePicker();" onblur="" />
                    <?php }?>
                </div>
            </div>
            <!--<div class='form-group row'>
                <label for="exampleInputName2" class="_label">Banner图:</label>
                <?php if($actions['id']>0){?>
                <input type='hidden' name='banner_logo' id='banner_logo' value="<?php echo $actions['logo'];?>">
                <img src="<?php echo $actions['logo'];?>" style="width:30rem;height: 10rem;border:1px;border-color: black" id="_banner_"/>
                <?php }else{?>
                <input type='hidden' name='banner_logo' id='banner_logo' value='/public/images/logo.jpeg'>
                <img src="/public/images/logo.jpeg" style="width:30rem;height: 10rem;border:1px;border-color: black" id="_banner_"/>
                <?php }?>
                <iframe src="/home/action/img" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem"></iframe>
                <span class="_prompt">宣传用图片建议长宽比例3:1；2M以内，支持“jpg,jpeg,png,gif”</span>
            </div>-->
            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">是否允许重复购买:</label>
                <input type="radio" name="only" value="2" <?php if($actions['only']==2){ echo 'checked=checked'; } ?> >允许
                <input type="radio" name="only" value="1" <?php if($actions['only']==1){ echo 'checked=checked'; } ?> >不允许
                <!--<?php if(!empty($actions)){?>
                <input type="text" class="row _minput" name='action_name' placeholder="" value="<?php echo $actions['action_name'];?>"/>
                <?php }else{?>
                <input type="text" class="row _minput" name='action_name' placeholder="" value=""/>
                <?php } ?>-->
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2" class="_label">活动介绍:</label>
                <?php if(!empty($actions)){?>
                <textarea name='intro' id="_intro" class="_textarea"><?php echo $actions['intro']; ?></textarea>
                <?php }else{?>
                <textarea name='intro' id="_intro" class="_textarea"></textarea>
                <?php }?>
            </div>
            <div class="form-group _submit_div row">
                <?php if($actions['id']>0 && $copy==false){?>
                <input name='id' type='hidden' value="<?php echo $actions['id'];?>"/>
                <?php }?>
                <input name='create' id='create' class='_button' type="button" value="预览" onclick="_submit(2);"/>
                <input name='caogao' id='caogao' class='_button' type="submit" value="保存草稿" onsubmit="return _submit(1);"/>
            </div>
        </form>
</div>
<script type='text/javascript' src='/public/js/date/WdatePicker.js'></script>
<script type='text/javascript'>
    function del_item(obj,id){
        $(obj).parent().parent().parent().parent().remove();
        $("#items_"+id).remove();
    }
    
    function getItem(store_id){
        var img_domain = "http://<?php echo IMAGE_DOMAIN;?>";
        $.ajax({
            url: "/home/action/items?store_id=" + store_id,
            async: true,
            success: function (data) {
                if (data == 'false') {
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>选择商品</option>";
                var str2 = '';
                $.each(data, function (i, v) {
                    var image = '';
                    str += "<option value='" + v.id + "'>" + v.name + "</option>";
                    $.each(v.images,function (ii,vv){
                        if(ii==0){
                            image = img_domain+vv.image;
                            return false;
                        }
                    });
                    v.price = v.price/100;
                    str2 += "<input type='hidden' value='"+v.id+"' id='item_"+v.id+"' _name='"+v.name+"' img='"+image+"' _img='/public/images/"+v.img+"' price='"+v.price+"'>";
                });
                $('#item_select').html(str);
                $('body').append(str2);
            }
        });
    }
                    $(document).ready(function () {
                        var store_id = $("#store_id").val();
                        if(store_id>0){
                            getItem(store_id);
                        }
                        
                        $('#item_select').click(function(){
                            if($('#create_good').next().val()){
                                getItem(store_id);
                                $('#create_good').next().remove();
                            }
                            
                        });
                        
                        $('#create_good').click(function(){
                            var htmls = "<input type='hidden' name='st' value='1' >";
                            $(this).parent().append(htmls);
                            window.open("/home/goods/create");  
                        });
                        var id = $('#type').val();
                        var str = $('#model_' + id).val();
                        $("#_intro").html(str);
                        var item_name = $('#item_name');
                        var items = $('#item');
                        var barber = $('#_barber');



                        $("#type").change(function () {
                            var id = $('#type').val();
                            var str = $('#model_' + id).val();
                            
                            $("#_intro").html(str);
                            if (id == 1) {
                                $('#barber_par').html(barber);
                                $('#type_model').html(item_name);
                                $('#type_model').append(items);
                            }else{
                                var link = $('#model_type_'+id).attr("url");
                                window.location.href = '/home/action/create?model_id='+id+'&model='+link;
                                return;
                            }
//                            if ( id == 2 ) {
//                                window.location.href= '/home/action/face';
//                                return;
//                            }
                            window.location.reload();
                        });


                        $("#store_id").change(function () {
                            store_id = $("#store_id").val();
                            $.ajax({
                                url: "/home/action/getbarber?store_id=" + store_id,
                                async: true,
                                success: function (data) {
                                    if (data == 'false') {
                                        return;
                                    }
                                    data = eval('(' + data + ')');
                                    var str = "<option value='0'>全部</option>";
                                    $.each(data, function (i, v) {
                                        str += "<option value='" + v.id + "'>" + v.name + "</option>"
                                    });
                                    $('#barber').html(str);
                                }
                            });
                            getItem(store_id);
                        });
                        
                        $("#add_item").click(function(){
                            var len = $("#item_list").children().length;
                            if(len>=3){
                                alert("只能添加3件商品哦");
                                return false;
                            }
                            var id = $('#item_select').val();
                            if(id<1){
                                alert("请先选中一件商品");
                                return false;
                            }
                            var image = $("#item_"+id).attr('img');
                            var name = $("#item_"+id).attr('_name');
                            var _img = $("#item_"+id).attr("_img");
                            var price = $("#item_"+id).attr("price");
                            var html = '<div class="col-sm-4 col-md-3 full" style="margin-left:6rem;" ><div class="thumbnail" style="margin-bottom:10px;"><div style="height:15rem;overflow: hidden;text-align:center"><img class="_img" src="';
                            html += image;
                            html += '"style="width:100%;height:100%"></div></div>';
                            
                            html += '<div class="caption" style="overflow: hidden"><div style="font-size:1.8rem"><div><img class="_img" src="';
                            html += _img;
                            html += '" style="width:28%;"><span style="margin-left: 6px;font-size:2rem;">';
                            html += name;
                            html += '<div>价格：'+price+'&nbsp;元</div><div>活动价：<input type="text" value="" style="width:30%" name="real_price[]">&nbsp;元</div>';
                            html += '</span></div><div style="text-align:right"><a onclick="del_item(this,'+id+');" href="#">删除</a></div></div></div></div>';
                            $("#item_list").append(html);
                            var _html = "<input type='hidden' id='items_"+id+"' value='"+id+"' name='items[]'>";
                            $("#form").append(_html);
                        });

                        $("#form").validate({
                            rules: {
                                store_id: {
                                    required: true,
                                    min: 1,
                                },
                                action_name: {
                                    required: true,
                                },
                                type: {
                                    required: true,
                                    number: true
                                },
                                start_time: {
                                    required: true,
                                },
                                end_time: {
                                    required: true,
                                },
                                intro: {
                                    required: true,
                                },
                                only: {
                                    required: true,
                                }


                            },
                            messages: {
                                store_id: {
                                    required: "请选择店铺",
                                    min: "请选择店铺",
                                },
                                action_name: {
                                    required: '请输入活动名称',
                                },
                                type: {
                                    required: '请选择活动类型',
                                },
                                start_time: {
                                    required: '请选择活动开始日期',
                                },
                                end_time: {
                                    required: '请选择活动结束日期',
                                },
                                intro: {
                                    required: '请填写活动介绍',
                                },
                                only: {
                                    required: '请选择是否允许购买',
                                }
                            },
                            errorPlacement: function (error, element) { //指定错误信息位置
                                if (element.is(':radio') ) { //如果是radio或checkbox
                                    var eid = element.attr('name'); //获取元素的name属性
                                    error.appendTo(element.parent()); //将错误信息添加当前元素的父结点后面
                                } else {
                                    error.insertAfter(element);
                                }
                            }
                        });                    
                    })


                    function _submit(type) {
                        if (type == 1) {
                            $('#create').remove();
                        } else {
                            $('#caogao').remove();
                        }
                        var content = $("#_intro").val();
                        content = content.replace(/<br\/>/,"\n");
                        content = content.replace(/<span style=\'color:red\'>/,"");
                        content = content.replace(/<\/span>/,"");
                        content = content.replace(/\n/g, "<br/>");
                        content = content.replace(/[\d]{1,}/g, "<span style='color:red'>$&</span>");
                        $("#_intro").val(content);
                        $('#form').submit();
                    }


              

                




</script>
<style>.error{padding-left:2rem}</style>
</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>